<?php
header('content-type:text/html;charset=utf-8');
include '../base.php';
$name=$_POST['name'];
$password=$_POST['password'];
$id=$_POST['id'];
$class=$_POST['class'];
$sex=$_POST['sex'];
$phone_num=$_POST['phone_num'];
$major=$_POST['major'];
$room_num=$_POST['room_num'];
$port=array('status'=>'0','msg'=>'error','data'=>'');
$sql="SELECT id FROM user WHERE id='$id'";
$result=mysqli_query($conn, $sql);
$num = mysqli_num_rows($result); 
if($num){
	$port['data']='学号已存在,注册失败';
	echo json_encode($port);
 	exit;
}
$insert_sql="INSERT INTO user (id,password,name,class,phone_num,sex,major,room_num) VALUES('$id', '$password', '$name', '$class', '$phone_num', '$sex', '$major', '$room_num')";
$result_insert=mysqli_query($conn, $insert_sql);
if($result_insert){
	$port['msg']='注册成功';
	$port['status']='1';
	$port['data']='注册成功';
	echo json_encode($port);
	exit;
}else {
	$port['data']='注册失败';
	echo json_encode($port);
 	exit;
}
mysqli_close($conn);
?>